package com.cc.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class JdbcConfig {
    @Value("com.mysql.cj.jdbc.Driver")
    private String driver;
    @Value("jdbc:mysql://localhost:3306/emp_db?characterEncoding=UTF-8&&serverTimezone=Asia/Shanghai&&useSSL=false")
    private String url;
    @Value("root")
    private String uname;
    @Value("1234")
    private String password;

    @Bean
    public DataSource dataSource(){
        //创建数据源对象
        DruidDataSource dataSource = new DruidDataSource();
        //设置驱动
        dataSource.setDriverClassName(driver);
        //设置连接地址
        dataSource.setUrl(url);
        //设置用户名
        dataSource.setUsername(uname);
        //设置密码
        dataSource.setPassword(password);
        return dataSource;
    }
}
